<?php
declare(strict_types=1);

namespace App\Controller\Admin\V1\Media;

use App\Controller\Admin\AdminController;
use App\Repositories\AlbumRepository;
use App\Repositories\FileRepository;
use Hyperf\Di\Annotation\Inject;
class AlbumController extends AdminController
{

    public function all()
    {
        $datas = AlbumRepository::getInstance()->all();
        $datas = $datas->toArray();
        $datas = array_merge([['id'=>0,'name'=>'默认相册']],$datas);
        return $this->response->success($datas);
    }

    public function pictures()
    {
        $album_id = (int)$this->request->input('id',0);
        $rows = $this->request->input('rows',10);
        $search['album_id']=[
            'field' => 'album_id',
            'value' => $album_id,
        ];
        $search['is_image']=[
            'field' => 'is_image',
            'value' => 1
        ];
        $orderBy= [
            [
                'field' => 'id',
                'sort' => 'desc'
            ]
        ];
        $datas =FileRepository::getInstance()->getList('*',$search,['limit'=>$rows],$orderBy);
        return $this->response->success($datas);
    }

}
